import ImgView from '@/biz-components/img-view';
import PdfView from '@/biz-components/pdf-view';

import { Empty } from 'antd';
import { FC } from 'react';

export const IMG_TYPE = ['.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG', '.bmp', '.BMP', ".SVG", ".svg"];
export const PDF_TYPE = ['.pdf', 'pdf'];

interface ViewContainerProps {
  type: string;
  height?: number | string;
  fileUrl: string;
}

const ViewContainer: FC<ViewContainerProps> = ({ type, height, fileUrl }) => {

  const typeLowerCase = type?.toLocaleLowerCase();

  if (IMG_TYPE.includes(typeLowerCase)) {
    return <ImgView images={fileUrl} height={height} width="100%" />;
  }

  if (PDF_TYPE.includes(typeLowerCase)) {
    return <PdfView fileUrl={fileUrl} height={height} />;
  }

  return <Empty description="暂未支持预览" />;
};

ViewContainer.defaultProps = {
  height: 500,
};

export default ViewContainer;
